package ace.cmp.easycaptcha.autoconfigure;

import ace.cmp.easycaptcha.core.properties.EasyCaptchaProperties;
import ace.cmp.easycaptcha.core.service.EasyCaptchaFactory;
import ace.cmp.easycaptcha.core.service.impl.EasyCaptchaFactoryImpl;
import com.wf.captcha.base.Captcha;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author caspar
 * @date 2023/3/4 9:39
 */
@AllArgsConstructor
@EnableConfigurationProperties({EasyCaptchaProperties.class})
@Configuration
public class EasyCaptchaAutoConfigure {
  private final EasyCaptchaProperties properties;

  @Bean
  @ConditionalOnMissingBean
  public Captcha defaultEasyCaptcha(EasyCaptchaFactory easyCaptchaFactory) {
    return easyCaptchaFactory.create(properties);
  }

  @Bean
  @ConditionalOnMissingBean
  public EasyCaptchaFactory easyCaptchaFactory() {
    return new EasyCaptchaFactoryImpl();
  }
}
